15. Exercise: Create an Adapter

Creating an Adapter

In this Exercise, you will get to create an adapter to populate the recyclerview with values.

Exercise Code

Exercise:T03.03-Exercise-RecyclerViewAdapter

Create Adapter

And now you get to create an Adapter! Mostly. I've got you started by creating the class, but you get to fill it out by completing these tasks.

SOLUTION:
  • Add a mNumberItems member variable to GreenAdapter.java
  • Implement a constructor that sets the mNumberItems variable.
  • Make GreenAdapter extend RecyclerView.Adapter with the type parameter of our NumberViewHolder
  • Override onCreateViewHolder to return the new ViewHolder and inflate the item Layout
  • Override onBindViewHolder and call the bind function in our ViewHolder.
  • Override getItemCount to return our mNumberItems variable